﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP20.ViewModels
{
    public class WeightCheckViewModel : BaseViewModel
    {


        public WeightCheckViewModel(IRegionManager regionManager) : base(regionManager)
        {

            InitParam();
            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();
        }

        private void InitParam()
        {
            ST1SettingTime = WeightTime_Global.ST1WeightSettingTime;
            ST6SettingTime = WeightTime_Global.ST6WeightSettingTime;
            ST11SettingTime = WeightTime_Global.ST11WeightSettingTime;
        }

        private void OnTick(object? sender, EventArgs e)
        {
            ST1CurrentValue = OtherDevicePLCToPC_Global.testDatas[3].CurrentValue;
            ST6CurrentValue = OtherDevicePLCToPC_Global.testDatas[4].CurrentValue;
            ST11CurrentValue = OtherDevicePLCToPC_Global.testDatas[5].CurrentValue;

            ST1ResultValue = OtherDevicePLCToPC_Global.testDatas[3].ResultValue;
            ST6ResultValue = OtherDevicePLCToPC_Global.testDatas[4].ResultValue;
            ST11ResultValue = OtherDevicePLCToPC_Global.testDatas[5].ResultValue;

        }

        #region 事件


        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "ST1SettingTime":
                    WeightTime_Global.ST1WeightSettingTime = ST1SettingTime;
                    break;

                case "ST6SettingTime":
                    WeightTime_Global.ST6WeightSettingTime = ST6SettingTime;
                    break;

                case "ST11SettingTime":
                    WeightTime_Global.ST11WeightSettingTime = ST11SettingTime;
                    break;
                default:
                    break;
            }
        }


        private DelegateCommand _ST1Reset0DownCmd;
        public DelegateCommand ST1Reset0DownCmd =>
            _ST1Reset0DownCmd ?? (_ST1Reset0DownCmd = new DelegateCommand(ExecuteST1Reset0DownCmd));

        void ExecuteST1Reset0DownCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[0] = true;
        }


        private DelegateCommand _ST1Reset0UpCmd;
        public DelegateCommand ST1Reset0UpCmd =>
            _ST1Reset0UpCmd ?? (_ST1Reset0UpCmd = new DelegateCommand(ExecuteST1Reset0UpCmd));

        void ExecuteST1Reset0UpCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[0] = false;
        }


        private DelegateCommand _ST6Reset0DownCmd;
        public DelegateCommand ST6Reset0DownCmd =>
            _ST6Reset0DownCmd ?? (_ST6Reset0DownCmd = new DelegateCommand(ExecuteST6Reset0DownCmd));

        void ExecuteST6Reset0DownCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[1] = true;
        }

        private DelegateCommand _ST6Reset0UpCmd;
        public DelegateCommand ST6Reset0UpCmd =>
            _ST6Reset0UpCmd ?? (_ST6Reset0UpCmd = new DelegateCommand(ExecuteST6Reset0UpCmd));

        void ExecuteST6Reset0UpCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[1] = false;
        }

        private DelegateCommand _ST11Reset0DownCmd;
        public DelegateCommand ST11Reset0DownCmd =>
            _ST11Reset0DownCmd ?? (_ST11Reset0DownCmd = new DelegateCommand(ExecuteST11Reset0DownCmd));

        void ExecuteST11Reset0DownCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[2] = true;
        }

        private DelegateCommand _ST11Reset0UpCmd;
        public DelegateCommand ST11Reset0UpCmd =>
            _ST11Reset0UpCmd ?? (_ST11Reset0UpCmd = new DelegateCommand(ExecuteST11Reset0UpCmd));

        void ExecuteST11Reset0UpCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[2] = false;
        }
        #endregion

        #region 属性

        private float _ST1CurrentValue;
        public float ST1CurrentValue
        {
            get { return _ST1CurrentValue; }
            set { SetProperty(ref _ST1CurrentValue, value); }
        }

        private float _ST1ResultValue;
        public float ST1ResultValue
        {
            get { return _ST1ResultValue; }
            set { SetProperty(ref _ST1ResultValue, value); }
        }

        private short _ST1SettingTime;
        public short ST1SettingTime
        {
            get { return _ST1SettingTime; }
            set { SetProperty(ref _ST1SettingTime, value); }
        }


        private float _ST6CurrentValue;
        public float ST6CurrentValue
        {
            get { return _ST6CurrentValue; }
            set { SetProperty(ref _ST6CurrentValue, value); }
        }

        private float _ST6ResultValue;
        public float ST6ResultValue
        {
            get { return _ST6ResultValue; }
            set { SetProperty(ref _ST6ResultValue, value); }
        }

        private short _ST6SettingTime;
        public short ST6SettingTime
        {
            get { return _ST6SettingTime; }
            set { SetProperty(ref _ST6SettingTime, value); }
        }


        private float _ST11CurrentValue;
        public float ST11CurrentValue
        {
            get { return _ST11CurrentValue; }
            set { SetProperty(ref _ST11CurrentValue, value); }
        }

        private float _ST11ResultValue;
        public float ST11ResultValue
        {
            get { return _ST11ResultValue; }
            set { SetProperty(ref _ST11ResultValue, value); }
        }

        private short _ST11SettingTime;
        public short ST11SettingTime
        {
            get { return _ST11SettingTime; }
            set { SetProperty(ref _ST11SettingTime, value); }
        }


        #endregion

    }
}
